package com.wan.commonsdk;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.widget.PopupWindow;

public class Conet {

	public static final String HTTP = "http://";
	public static final String WAN51 = ".51wan.com/";
	public static final String MMANAGERT = "mmanager";
	// 初始化
	public static final String INIT_URL = HTTP + MMANAGERT + WAN51
			+ "index.php?g=Api&m=Pageapi&a=gameInformation&platformgid=";

	public static final String USER = "user";
	public static final String PASSPORTT = "passport";
	// 登陆地址
	public static final String LOGIN_URL = HTTP + USER + WAN51
			+ "api_microuser_appLogin_0.html";
	// 获取手机验证码
	public static final String SEND_PHONE_CODE_URL = HTTP + USER + WAN51

	+ "api_microuser_sendPhoneCode_0.html";

	// http://user.51wan.com/api_microuser_sendPhoneCode_0.html
	// public static final String GUEST_LOGIN_URL =
	// HTTP+USER+WAN51+"api_microuser_touristReg_0.html";
	// 游客登录
	public static final String Guest_RES_RUL = "http://passport.51wan.com/api_microuser_newtouristReg_0.html";
	// 绑定邮箱
	public static final String BIND_MOBILE_URL = HTTP + USER + WAN51
			+ "api_microuser_checkPhoneCode_0.html";
	// 更换密码
	public static final String UPDATE_PASSWORD_URL = HTTP + USER + WAN51
			+ "api_microuser_updateReg_0.html";
	// 注册
	public static final String GAME_REG_URL = HTTP + USER + WAN51
			+ "api_microuser_appGameReg_0.html";
	// 获取玩家信息
	public static final String USER_INFO_URL = HTTP + USER + WAN51
			+ "api_microuser_userInfo_0.html";
	// 支付
	public static final String PAY = "pay";
	// 获取订单信息
	public static final String PAY_ORDER_URL = HTTP + PAY + WAN51
			+ "index.php?module=common&control=phone&action=createOrder";
	// 活动接口
	public static final String Active_URL = HTTP + "hd.51wan.com/pvcount.php";
	// 绑定手机
	public static final String BING_PHONE_URL = "http://passport.51wan.com/api_microuser_getBindPhone_0.html";
	// 支付宝回调地址
	public static String ALIPAY_URL = HTTP + PAY + WAN51
			+ "channel/alipayphone/notify.php";
	// 微信支付回调地址
	public static final String WX_NOTIFIY_URL = HTTP + PAY + WAN51
			+ "channel/wechatpay/topay/notify.php";
	// 游客登录验证
	public static final String Guest_LOGIN_CC = "http://user.51wan.com/api_directuser_directUserCheck_0.html";
	// 优惠券地址
	public static final String YHQListUrl = "http://cx.51wan.com/index.php?module=interface&control=usercodes&action=getUserGiftcode";
	public static WanAppInfo mWanAppInfo = null;
	// 手机注册
	public static final String PhoneRegesterUrl = "http://passport.51wan.com/api_microuser_mobileReg_0.html";
	// 手机验证
	public static final String PhoneCheckUrl = "http://passport.51wan.com/reg_index_check_0.html?type=username&username=";
	// 优惠券兑换码
	public static final String YHQCodeUrl = "http://cx.51wan.com/index.php?module=interface&control=usercodes&action=gCodeAuth";
	public static UserInfo mUserInfo;
	public static Activity mActivity;
	public static final String SPUSER = "WANSDKUSERINFO";
	public static final String SPWANINFO = "WANSDKGAMEINFO";
	public static SharedPreferences WANSP;
	public static SharedPreferences TrackingIOSP;
	public static String serviceID = "11224";
	public static Activity payactivity;
	public static String imei;
	public static String who = "";
	public static String who_type = "";
	public static String TrakingAppId = "";
	public static String TrakingtuiId = "";
	public static int gameID;

	public List<Activity> activityLists = new ArrayList<Activity>();
	private static Conet instance;

	public static int isJZPW = 0;

	public static Conet getInstance() {
		if (null == instance) {
			instance = new Conet();
		}
		return instance;
	}

	public void exit() {
		if (activityLists != null) {
			for (Activity activity : activityLists) {
				if (!activity.isFinishing()) {
					activity.finish();
				}
			}
		}
	}

	public void addActivity(Activity activity) {
		activityLists.add(activity);
	}

	public static void saveuserInfo() {
		try {
			Editor edit = Conet.WANSP.edit();
			JSONObject jsonObject = new JSONObject();
			// private String user_id;
			// private String access_token;
			// private boolean isGuest;
			// private String user_name;
			// private String user_password;
			// private String bind_Phone
			jsonObject.put("user_id", Conet.mUserInfo.getUser_id());
			jsonObject.put("access_token", Conet.mUserInfo.getAccess_token());
			jsonObject.put("user_name", Conet.mUserInfo.getUser_name());
			jsonObject.put("user_password", Conet.mUserInfo.getUser_password());
			jsonObject.put("bind_Phone", Conet.mUserInfo.getBind_Phone());
			edit.putString(Conet.SPUSER, jsonObject.toString());
			edit.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Activity getmActivity() {
		return mActivity;
	}

	// public static Activity getpayActivity() {
	//
	// return payactivity;
	// }
}
